using System;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;
using OracleInternal.Network;

namespace OracleInternal.TTC
{
	internal class TTCOPing : TTCFunction
	{
		internal TTCOPing(MarshallingEngine mEngine)
			: base(mEngine, 147, 0)
		{
		}

		internal void Write()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCOPing, OracleTraceFuncName.Write);
			}
			try
			{
				WriteFunctionHeader();
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCOPing, OracleTraceFuncName.Write, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCOPing, OracleTraceFuncName.Write);
				}
			}
		}

		internal void ReadResponse()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCOPing, OracleTraceFuncName.ReadResponse);
			}
			bool flag = false;
			try
			{
				m_marshallingEngine.TTCErrorObject.Initialize();
				while (!flag)
				{
					try
					{
						switch (m_marshallingEngine.UnmarshalSB1())
						{
						case 23:
							ProcessServerSidePiggybackFunction(0);
							break;
						case 9:
							if (m_marshallingEngine.HasEOCSCapability)
							{
								m_marshallingEngine.m_endOfCallStatus = m_marshallingEngine.UnmarshalUB4();
							}
							if (m_marshallingEngine.HasFSAPCapability)
							{
								m_marshallingEngine.m_endToEndECIDSequenceNumber = m_marshallingEngine.UnmarshalUB2();
							}
							flag = true;
							break;
						case 15:
							m_marshallingEngine.TTCErrorObject.ReadWarning();
							break;
						case 4:
							m_marshallingEngine.TTCErrorObject.ReadErrorMessage();
							flag = true;
							break;
						default:
							throw new Exception("TTC Error: Unexpected Packet Received");
						}
					}
					catch (NetworkException ex)
					{
						if (ex.ErrorCode != 3111)
						{
							throw;
						}
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
					catch (Exception)
					{
						if (m_marshallingEngine.m_oraBufRdr != null)
						{
							m_marshallingEngine.m_oraBufRdr.ClearState();
						}
						m_marshallingEngine.m_oracleCommunication.Break();
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
				}
			}
			catch (Exception ex3)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCOPing, OracleTraceFuncName.ReadResponse, ex3);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCOPing, OracleTraceFuncName.ReadResponse);
				}
			}
		}
	}
}
